#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Charles.chen
# createDate:2017/9/5
# Title: 配置文件单例类
# Tip:
import ConfigParser
import os

class ConfigSingle(object):
    _instance = None
    configuration = None

    def __init__(self):
        if self.configuration is None:
            self.configuration = ConfigParser.ConfigParser()
            with open("config.ini") as fp:
                self.configuration.readfp(fp)
            pass
        pass

    def __new__(cls, *args, **kwargs):
        if ConfigSingle._instance is None:
            ConfigSingle._instance = object.__new__(cls, *args, **kwargs)
        return ConfigSingle._instance

    def flushConfig(self):
        with open('config.ini', 'w') as fp:
            self.configuration.write(fp)
            pass
        pass

    pass

def updateProjectConfig():
    pass



if __name__ == '__main__':
    c1 = ConfigSingle()
    c2 = ConfigSingle()
    print c1.configuration.get("super_user", "default_account")
    print id(c1)
    print id(c2)

    pass